<?php
/**
 * DMFramework
 * 
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @url http://dmframework.nl
 */

/**
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @package System.Library.Acl
 */
class Dmf_Acl_Resource
{
    /**
     * Name of the resource 
     * 
     * @var string 
     */
    private $_name;
    
    /**
     * All actions
     * 
     * @var array 
     */
    private $_actions = array();
    
    /**
     * Constructor
     * 
     * @param string $name 
     */
    public function __construct( $name )
    {
        $this->_name = $name;
    }
    
     /**
     * Get Role name
     * 
     * @return string
     */
    public function getName()
    {
        return $this->_name;
    }
    
    /**
     * Add action to a resource
     * 
     * @param string $name 
     */
    public function addAction( $name )
    {
        $this->_actions[] = ( $name instanceof Dmf_Acl_Action ) ? $name : new Dmf_Acl_Action( $name );
    }
    
    /**
     * Add actions to an resource
     * 
     * @param array $actions 
     */
    public function addActions( $actions )
    {
        foreach( $actions as $action )
        {
            $this->addAction( $action );
        }
    }
    
    /**
     * If the action exist
     * 
     * @param string $name
     * @return boolean 
     */
    public function isAction( $name )
    {
        foreach( $this->_actions as $action )
        {
            if ( $action->getName() == $name || $action->getName() == '*' )
            {
                return true;
            }
        }
        
        return false;
    }
}